package com.app.micaihu.bean.topic;

import android.graphics.Bitmap;
import android.text.TextUtils;

import com.app.micaihu.app.AppApplication;
import com.app.micaihu.configure.AppConfigTools;
import com.app.utils.util.file.AppFileUtils;
import com.app.utils.util.image.ImageUtils;

import java.io.File;

/**
 * 发表的图片
 *
 * @author linkai
 */
public class SendImageBean {
    private File file;
    private Bitmap image;
    private String path;
    private boolean isShowDel;// 是否显示删除图片


    public SendImageBean() {
    }

    /**
     * 传入path 设置file和image
     *
     * @param path
     */
    public SendImageBean(String path) {
        this.path = path;
        if (!TextUtils.isEmpty(path)) {

            try {
                // 得到当前时间戳的图片
                file = AppFileUtils.createMediaFile(AppApplication.getInstance(), AppConfigTools.USERSAVEIMG);
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (file != null) {
                image = ImageUtils.sampBitmap4(path);

                if (image == null) {
                    return;
                }
                boolean b = ImageUtils.saveBitmap2file(image, file);
                if (!b) {
                    if (file.exists()) {
                        file.delete();
                    }
                    image = null;
                    file = null;
                    return;
                }

            }
        }
    }

    public Bitmap getImage() {
        return image;
    }

    public void setImage(Bitmap image) {
        this.image = image;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public boolean isShowDel() {
        return isShowDel;
    }

    public void setShowDel(boolean isShowDel) {
        this.isShowDel = isShowDel;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

}
